#include <bits/stdc++.h>
// 2025/01/16
// tag: 
using namespace std;

int n, m, cnt, ans, essay[100001];
int have[100001];
map<string, int> hayek;

signed main()
{
    cin >> n;
    for (int i = 1; i <= n; i++){
        string s;
        cin >> s;
        if (hayek.count(s) == 0)
            hayek[s] = ++cnt;
    }
    cin >> m;
    for (int i = 1; i <= m; i++){
        string s;
        cin >> s;
        if (hayek.count(s) == 0)
            hayek[s] = ++cnt;
        essay[i] = hayek[s];
        if (essay[i] <= n)
            have[essay[i]] = true;
    }
    for (int i = 1; i <= n; i++)
        ans += have[i];
    int l = 0, r = 0, c = 0, ans2 = INT_MAX;
    memset(have, 0, sizeof(have));
    while (r <= m){
        if (c < ans){
            r++;
            if (essay[r] <= n)
                c += (have[essay[r]] == 0);
            have[essay[r]]++;
        }
        else{
            ans2 = min(ans2, r - l + 1);
            if (essay[l] <= n)
                c -= (have[essay[l]] == 1);
            have[essay[l]]--;
            l++;
        }
    }
    cout << ans << endl << ans2 << endl;
    return 0;
}